package com.xysl.api.factory;

import com.xysl.api.RemoteXyslUserService;
import com.xysl.api.domain.XyslUser;
import com.xysl.api.model.XyslLoginUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import com.ruoyi.common.core.domain.R;

import java.util.Set;


/**
 * 用户服务降级处理
 *
 * @author ruoyi
 */
@Component
public class RemoteXyslUserFallbackFactory implements FallbackFactory<RemoteXyslUserService>
{
    private static final Logger log = LoggerFactory.getLogger(RemoteXyslUserFallbackFactory.class);

    @Override
    public RemoteXyslUserService create(Throwable throwable)
    {
        log.error("用户服务调用失败:{}", throwable.getMessage());
        return new RemoteXyslUserService()
        {
            @Override
            public R<XyslLoginUser> getXyslUserInfo(String account, String source)
            {
                return R.fail("获取用户失败:" + throwable.getMessage());
            }

            @Override
            public R<Boolean> registerUserInfo(XyslUser xyslUser, String source)
            {
                return R.fail("注册用户失败:" + throwable.getMessage());
            }

            @Override
            public R<Boolean> recordUserLogin(XyslUser xyslUser, String source)
            {
                return R.fail("记录用户登录信息失败:" + throwable.getMessage());
            }

            @Override
            public R<Set<String>> getRolePermission(XyslUser xyslUser, String source) {
                return R.fail("记录获取用户角色信息失败:" + throwable.getMessage());
            }

            @Override
            public R<Set<String>> getMenuwPermission(XyslUser xyslUser, String source) {
                return R.fail("记录获取用户菜单权限信息失败:" + throwable.getMessage());
            }
        };
    }
}
